package com.wb.oldwomen;

import android.view.MotionEvent;

import com.wb.fw.GateActivity;
import com.wb.fw.Global;
import com.wb.fw.IConstants;
import com.wb.fw.SoundManager;
import com.wb.fw.Util;
import com.wiyun.engine.nodes.Button;
import com.wiyun.engine.nodes.ColorLayer;
import com.wiyun.engine.nodes.Sprite;
import com.wiyun.engine.opengl.Texture2D;

public class UIHelp extends ColorLayer implements IConstants {
	public static UIHelp make(GameScene parent) {
		return new UIHelp(parent);
	}
	GameScene mparent;
	int mlastState;
	int mcurHlepPage;
	Sprite mpage;
	protected UIHelp(GameScene parent) {
		mparent = parent;
		setKeyEnabled(true);
		setTouchEnabled(true);
	}

	public void setEnterState(int mGameStatue) {
		mlastState = mGameStatue;
		
		mcurHlepPage = 0;
		mpage = Sprite.make(R.drawable.help1);
		mpage.autoRelease();
		mpage.setScale(Global.sScaleRate);
		mpage.setPosition(Global.sWYSize.width/2, Global.sWYSize.height/2);
		addChild(mpage, 0);
		
		Button next = Button.make(R.drawable.help_continue_n, R.drawable.help_continue_p, this, "xlnext"); 
		next.autoRelease();
		next.setScale(Global.sScaleRate);
		next.setAnchor(1f, 0f);
		next.setPosition(Global.sEndX-10*Global.sScaleRate, Global.sEndY + 10*Global.sScaleRate);
		addChild(next, 1);
	}
	
	public void xlnext() {
		SoundManager.clickMenuItem();
		mcurHlepPage ++;
		if (mcurHlepPage >= 3) {
			if (Util.isFirst(GateActivity.sInstance)) {
				mparent.switchState(GS_GAME_LEVEL_SELECT);
				Util.saveFirst(GateActivity.sInstance);
			} else {
				mparent.switchState(mlastState);
			}
		} else {
			removeChild(mpage, true);
			mpage = null;
			mpage = Sprite.make(R.drawable.help1 + mcurHlepPage);
			mpage.autoRelease();
			mpage.setScale(Global.sScaleRate);
			mpage.setPosition(Global.sWYSize.width/2, Global.sWYSize.height/2);
			addChild(mpage, 0);
		}
	}

	public void tick() {
		
	}
	
////////////////上面是模板/////////////////////////////
	@Override
	public boolean wyTouchesBegan(MotionEvent event) {
//		if (isVisible()) {
//			mparent.switchState(mlastState);
//			return true;
//		} else {
			return super.wyTouchesBegan(event);
//		}
	}

	@Override
	protected boolean onBackButton() {
		if (isVisible()) {
			mparent.switchState(mlastState);
		}
		return true;
	}
	
	
}
